﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsGame1.CoreComponents;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;


namespace WindowsGame1
{
    class CreatePCScreen : GameScreen
    {

        ButtonMenu buttonMenu;

        int className = 0;
        string name = "Raphael";
        bool gender = false;
        int difficultyIndex = 1;

        Texture2D buttonImage;
        Texture2D background;

        int screenWidth;
        int screenHeight;

        string[] menuItems = {"Change Name","Change Gender","Change Profession",
                              "Change Difficulty Level","Return to Start Screen","Begin the Adventure" };

       
        string[] difficultyLevels = Enum.GetNames(typeof(Level));
        Level difficultyLevel;

        string[] classNames = PlayerCharacter.ClassNames;
        CharClass characterClass = CharClass.Pirate;

        SpriteFont spriteFont;

        Texture2D[] playerTextures = new Texture2D[3];

        public CreatePCScreen(Game1 game)
            : base(game)
        {
            LoadContent();

            difficultyLevel = Difficulty.DifficultyLevel(difficultyIndex);

            Components.Add(new BackgroundComponent(game, background, true));

            buttonMenu = new ButtonMenu(game, spriteFont, buttonImage);
            buttonMenu.SetMenuItems(menuItems);
            Components.Add(buttonMenu);

            screenWidth = Game.Window.ClientBounds.Width;
            screenHeight = Game.Window.ClientBounds.Height;
        }

        protected override void LoadContent()
        {
            background = Content.Load<Texture2D>(@"Backgrounds\createpcscreen");
            buttonImage = Content.Load<Texture2D>(@"GUI\buttonbackground");
            spriteFont = Content.Load<SpriteFont>("normal");
            LoadPlayerSprites();
            base.LoadContent();
        }

        private void LoadPlayerSprites()
        {
            playerTextures[0] = Content.Load<Texture2D>(@"Sprites\pirate");
            playerTextures[1] = Content.Load<Texture2D>(@"Sprites\bountyhunter");
            playerTextures[2] = Content.Load<Texture2D>(@"Sprites\slavetrader");;
        }

        public Level DifficultyLevel
        {
            get { return difficultyLevel; }
        }

        public void ChangeDifficulty(int difficultyIndex)
        {
            this.difficultyIndex = difficultyIndex;
            difficultyLevel = Difficulty.DifficultyLevel(difficultyIndex);
        }

        public int SelectedIndex
        {
            get { return buttonMenu.SelectedIndex; }
        }

        public string Name
        {
            get { return name; }
        }

        public void ChangeName(string name)
        {
            this.name = name;
        }

        public bool Gender
        {
            get { return gender; }
        }

        public void ChangeGender(bool gender)
        {
            this.gender = gender;
        }

        public void ChangeClass(int className)
        {
            this.className = className;
            switch (className)
            {
                case 0:
                    characterClass = CharClass.Pirate;
                    break;
                case 1:
                    characterClass = CharClass.BountyHunter;
                    break;
                case 2:
                    characterClass = CharClass.SlaveTrader;
                    break;

            }
        }

        public CharClass CharacterClass
        {
            get { return characterClass; }
        }

        public bool CharacterGender
        {
            get { return gender; }
        }

        public string CharacterName
        {
            get { return name; }
        }

        public override void Show()
        {
            buttonMenu.Position = new Vector2((screenWidth -
            buttonMenu.Width) / 2,
            screenHeight - buttonMenu.Height - 10);
            base.Show();
        }

        public override void Draw(GameTime gameTime)
        {
            Vector2 position = new Vector2();
            string characterString;

            characterString = name + " the ";
            base.Draw(gameTime);
            characterString += classNames[className];
            Vector2 stringSize = spriteFont.MeasureString(characterString);
            position.X = (screenWidth - stringSize.X) / 2;
            position.Y = 0;
            spriteBatch.DrawString(spriteFont,characterString,position + Vector2.One * 3,Color.Black);
            spriteBatch.DrawString(spriteFont,characterString,position,Color.White);

            characterString = "Playing in " + difficultyLevels[difficultyIndex];
            characterString += " mode";

            stringSize = spriteFont.MeasureString(characterString);
            position.X = (screenWidth - stringSize.X) / 2;
            position.Y += spriteFont.LineSpacing;

            spriteBatch.DrawString(spriteFont, characterString, position + Vector2.One * 3, Color.Black);
            spriteBatch.DrawString(spriteFont, characterString, position, Color.White);
            position.Y = 200;
            position.X = (screenWidth - 64) / 2;

            spriteBatch.Draw(playerTextures[(int)characterClass], position, new Rectangle(0, 0, 64, 64), Color.White);
        }
    }
}